<div class="table-body">
    <table id="supplydetailTable" lay-filter="supplydetailTable"></table>
</div>

<script>
    layui.use(['table','form','layer','laydate'],function(){
        var layer = layui.layer, table = layui.table,form = layui.form,date = layui.laydate;
        // 定义变量保存当前页面和当前页面数据条数
        var currPage; 
        var dataNum;
        
        //执行渲染
        table.render({
            elem: '#supplydetailTable', //指定原始表格元素选择器（推荐id选择器）
            height: 'full-115',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            id:'supplydetailTable',
            url: "{:url('BookDraw/booksupplydrawdetail')}" + '?supplyid={$supplyid}',
            cols: [[ //标题栏
            { type: 'numbers' },
                { field: 'id', title: 'ID', hide:true},
                { field: 'supply_id', hide:true, title: 'supply_id'},
                { field: 'plan_id', hide:true, title: 'plan_id'},
                { field: 'book_name', title: '教材名称', width:200, align:'center'},
                { field: 'plan_price', title: '教材单价', width:100, align:'center'},
                { field: 'book_disc', title: '折扣价', width:100, align:'center'},
                { field: 'plan_book_num', title: '教材数量', width:100, align:'center'},
                { field: 'book_author', title: '主编', width:160, align:'center'},
                { field: 'book_concern', title: '出版社', width:180, align:'center'},
                { field: 'book_edition', title: '版次', width:160, align:'center'},
                { field: 'book_isbn', title: 'ISBN', width:160, align:'center'},
                { field: 'book_reward', title: '获奖情况', width:200, align:'center'},
                { field: 'book_date', title: '出版年限', width:120, align:'center'},
                {
                    field: 'option', title: '操作', templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-xs del layui-btn-danger" name="del" data-supply_id="' + d.supply_id + '" data-plan_id="' + d.plan_id + '">删除</a>'; 
                        return html;
                    }, align: 'center', width: 80
                }
            ]], //设置表头
            done: function(res, curr, count){
                // 给变量赋值 
                dataNum = res.data.length;
                currPage = curr;
            }
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        //删除申请
        $(document).on('click', '.del', function () { 
            var supply_id = $(this).attr('data-supply_id');
            var plan_id = $(this).attr('data-plan_id');
            $("a[name='del']").addClass("layui-btn-disabled");
            $("a[name='del']").attr("disabled", true);
            layer.confirm('您确定删除该补发明细吗？', {
                btn: ['确认', '取消'], //按钮
                cancel:function(index, layero){
                    $("a[name='del']").removeClass("layui-btn-disabled");
                    $("a[name='del']").removeAttr("disabled");
                }
            }, function () {
                JsPost("{:url('BookDraw/booksupplydelbook')}", {supply_id:supply_id, plan_id:plan_id}, function (res) {
                    $("a[name='del']").removeClass("layui-btn-disabled");
                    $("a[name='del']").removeAttr("disabled");
                    
                    //删除逻辑中判断只有一条数据时应该刷新前一页信息
                    layer.msg(res.msg);
                    if(res.status){
                        if(dataNum == 1){
                            currPage = currPage - 1;
                        }

                        table.reload('supplydetailTable', {
                            page: {
                                curr: currPage
                            }
                        });
                        return false;
                    }
                });
            }, function () {
                $("a[name='del']").removeClass("layui-btn-disabled");
                $("a[name='del']").removeAttr("disabled");
                layer.close(1);
            });
        }); 
    })
</script>
